home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Developer & Web Development Tools / Inno Setup 5.2.3 / isetup-5.2.3.exe / {app} / Examples / CodeDlg.iss (.txt) < prev    next >
Encoding:
Inno Setup Script  |  2006-10-03  |  7.3 KB  |  168 lines

  1. ; -- CodeDlg.iss --
  2. ; This script shows how to insert custom wizard pages into Setup and how to handle
  3. ; these pages. Furthermore it shows how to 'communicate' between the [Code] section
  4. ; and the regular Inno Setup sections using {code:...} constants. Finally it shows
  5. ; how to customize the settings text on the 'Ready To Install' page.
  6. [Setup]
  7. AppName=My Program
  8. AppVerName=My Program version 1.5
  9. DefaultDirName={pf}\My Program
  10. DisableProgramGroupPage=yes
  11. UninstallDisplayIcon={app}\MyProg.exe
  12. OutputDir=userdocs:Inno Setup Examples Output
  13. [Files]
  14. Source: "MyProg.exe"; DestDir: "{app}"
  15. Source: "MyProg.chm"; DestDir: "{app}"
  16. Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
  17. [Registry]
  18. Root: HKCU; Subkey: "Software\My Company"; Flags: uninsdeletekeyifempty
  19. Root: HKCU; Subkey: "Software\My Company\My Program"; Flags: uninsdeletekey
  20. Root: HKCU; Subkey: "Software\My Company\My Program\Settings"; ValueType: string; ValueName: "Name"; ValueData: "{code:GetUser|Name}"
  21. Root: HKCU; Subkey: "Software\My Company\My Program\Settings"; ValueType: string; ValueName: "Company"; ValueData: "{code:GetUser|Company}"
  22. Root: HKCU; Subkey: "Software\My Company\My Program\Settings"; ValueType: string; ValueName: "DataDir"; ValueData: "{code:GetDataDir}"
  23. ; etc.
  24. [Dirs]
  25. Name: {code:GetDataDir}; Flags: uninsneveruninstall
  26. [Code]
  27.   UserPage: TInputQueryWizardPage;
  28.   UsagePage: TInputOptionWizardPage;
  29.   LightMsgPage: TOutputMsgWizardPage;
  30.   KeyPage: TInputQueryWizardPage;
  31.   ProgressPage: TOutputProgressWizardPage;
  32.   DataDirPage: TInputDirWizardPage;
  33. procedure InitializeWizard;
  34. begin
  35.   { Create the pages }
  36.   UserPage := CreateInputQueryPage(wpWelcome,
  37.     'Personal Information', 'Who are you?',
  38.     'Please specify your name and the company for whom you work, then click Next.');
  39.   UserPage.Add('Name:', False);
  40.   UserPage.Add('Company:', False);
  41.   UsagePage := CreateInputOptionPage(UserPage.ID,
  42.     'Personal Information', 'How will you use My Program?',
  43.     'Please specify how you would like to use My Program, then click Next.',
  44.     True, False);
  45.   UsagePage.Add('Light mode (no ads, limited functionality)');
  46.   UsagePage.Add('Sponsored mode (with ads, full functionality)');
  47.   UsagePage.Add('Paid mode (no ads, full functionality)');
  48.   LightMsgPage := CreateOutputMsgPage(UsagePage.ID,
  49.     'Personal Information', 'How will you use My Program?',
  50.     'Note: to enjoy all features My Program can offer and to support its development, ' +
  51.     'you can switch to sponsored or paid mode at any time by selecting ''Usage Mode'' ' +
  52.     'in the ''Help'' menu of My Program after the installation has completed.'#13#13 +
  53.     'Click Back if you want to change your usage mode setting now, or click Next to ' +
  54.     'continue with the installation.');
  55.   KeyPage := CreateInputQueryPage(UsagePage.ID,
  56.     'Personal Information', 'What''s your registration key?',
  57.     'Please specify your registration key and click Next to continue. If you don''t ' +
  58.     'have a valid registration key, click Back to choose a different usage mode.');
  59.   KeyPage.Add('Registration key:', False);
  60.   ProgressPage := CreateOutputProgressPage('Personal Information',
  61.     'What''s your registration key?');
  62.   DataDirPage := CreateInputDirPage(wpSelectDir,
  63.     'Select Personal Data Directory', 'Where should personal data files be installed?',
  64.     'Select the folder in which Setup should install personal data files, then click Next.',
  65.     False, '');
  66.   DataDirPage.Add('');
  67.   { Set default values, using settings that were stored last time if possible }
  68.   UserPage.Values[0] := GetPreviousData('Name', ExpandConstant('{sysuserinfoname}'));
  69.   UserPage.Values[1] := GetPreviousData('Company', ExpandConstant('{sysuserinfoorg}'));
  70.   case GetPreviousData('UsageMode', '') of
  71.     'light': UsagePage.SelectedValueIndex := 0;
  72.     'sponsored': UsagePage.SelectedValueIndex := 1;
  73.     'paid': UsagePage.SelectedValueIndex := 2;
  74.   else
  75.     UsagePage.SelectedValueIndex := 1;
  76.   end;
  77.   DataDirPage.Values[0] := GetPreviousData('DataDir', '');
  78. procedure RegisterPreviousData(PreviousDataKey: Integer);
  79.   UsageMode: String;
  80. begin
  81.   { Store the settings so we can restore them next time }
  82.   SetPreviousData(PreviousDataKey, 'Name', UserPage.Values[0]);
  83.   SetPreviousData(PreviousDataKey, 'Company', UserPage.Values[1]);
  84.   case UsagePage.SelectedValueIndex of
  85.     0: UsageMode := 'light';
  86.     1: UsageMode := 'sponsored';
  87.     2: UsageMode := 'paid';
  88.   end;
  89.   SetPreviousData(PreviousDataKey, 'UsageMode', UsageMode);
  90.   SetPreviousData(PreviousDataKey, 'DataDir', DataDirPage.Values[0]);
  91. function ShouldSkipPage(PageID: Integer): Boolean;
  92. begin
  93.   { Skip pages that shouldn't be shown }
  94.   if (PageID = LightMsgPage.ID) and (UsagePage.SelectedValueIndex <> 0) then
  95.     Result := True
  96.   else if (PageID = KeyPage.ID) and (UsagePage.SelectedValueIndex <> 2) then
  97.     Result := True
  98.   else
  99.     Result := False;
  100. function NextButtonClick(CurPageID: Integer): Boolean;
  101.   I: Integer;
  102. begin
  103.   { Validate certain pages before allowing the user to proceed }
  104.   if CurPageID = UserPage.ID then begin
  105.     if UserPage.Values[0] = '' then begin
  106.       MsgBox('You must enter your name.', mbError, MB_OK);
  107.       Result := False;
  108.     end else begin
  109.       if DataDirPage.Values[0] = '' then
  110.         DataDirPage.Values[0] := 'C:\' + UserPage.Values[0];
  111.       Result := True;
  112.     end;
  113.   end else if CurPageID = KeyPage.ID then begin
  114.     { Just to show how 'OutputProgress' pages work.
  115.       Always use a try..finally between the Show and Hide calls as shown below. }
  116.     ProgressPage.SetText('Authorizing registration key...', '');
  117.     ProgressPage.SetProgress(0, 0);
  118.     ProgressPage.Show;
  119.     try
  120.       for I := 0 to 10 do begin
  121.         ProgressPage.SetProgress(I, 10);
  122.         Sleep(100);
  123.       end;
  124.     finally
  125.       ProgressPage.Hide;
  126.     end;
  127.     if KeyPage.Values[0] = 'inno' then
  128.       Result := True
  129.     else begin
  130.       MsgBox('You must enter a valid registration key. (Hint: The key is "inno".)', mbError, MB_OK);
  131.       Result := False;
  132.     end;
  133.   end else
  134.     Result := True;
  135. function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo,
  136.   MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
  137.   S: String;
  138. begin
  139.   { Fill the 'Ready Memo' with the normal settings and the custom settings }
  140.   S := '';
  141.   S := S + 'Personal Information:' + NewLine;
  142.   S := S + Space + UserPage.Values[0] + NewLine;
  143.   if UserPage.Values[1] <> '' then
  144.     S := S + Space + UserPage.Values[1] + NewLine;
  145.   S := S + NewLine;
  146.   S := S + 'Usage Mode:' + NewLine + Space;
  147.   case UsagePage.SelectedValueIndex of
  148.     0: S := S + 'Light mode';
  149.     1: S := S + 'Sponsored mode';
  150.     2: S := S + 'Paid mode';
  151.   end;
  152.   S := S + NewLine + NewLine;
  153.   S := S + MemoDirInfo + NewLine;
  154.   S := S + Space + DataDirPage.Values[0] + ' (personal data files)' + NewLine;
  155.   Result := S;
  156. function GetUser(Param: String): String;
  157. begin
  158.   { Return a user value }
  159.   { Could also be split into separate GetUserName and GetUserCompany functions }
  160.   if Param = 'Name' then
  161.     Result := UserPage.Values[0]
  162.   else if Param = 'Company' then
  163.     Result := UserPage.Values[1];
  164. function GetDataDir(Param: String): String;
  165. begin
  166.   { Return the selected DataDir }
  167.   Result := DataDirPage.Values[0];
  168.